<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class CreateCruiseOrderReportsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('cruise_check_details', function (Blueprint $table) {
            $table->id();
            $table->string('code', 32)->default('')->comment('报告编号');
            $table->unsignedInteger('orderId')->default(0)->comment('cruise_order.id');
            $table->unsignedInteger('taskId')->default(0)->comment('cruise_check_tasks.id');
            $table->unsignedInteger('sysTemplate')->default(0)->comment('模板类型 20常规 21专项');
            $table->unsignedInteger('checkType')->default(0)->comment('0常规/默认 1内部 2三方');

            $table->unsignedInteger('dealUid')->default(0)->comment('巡检人id');
            $table->string('dealName', 32)->default('')->comment('巡检人名称');
            $table->string('companyId', 64)->default('')->comment('机构id');
            $table->string('companyName', 32)->default('')->comment('机构名称');

            $table->unsignedSmallInteger('totalNum')->default(0)->comment('总项');
            $table->unsignedSmallInteger('failNum')->default(0)->comment('不合格项');
            $table->unsignedSmallInteger('totalScore')->default(0)->comment('模板总分');
            $table->unsignedSmallInteger('successScore')->default(0)->comment('合格线');
            $table->unsignedSmallInteger('actualScore')->default(0)->comment('实际得分');
            $table->tinyInteger('reportResult')->default(0)->comment('巡检结果 0初始化 1合格 2不合格 3已作废');
            $table->tinyInteger('veto')->default(0)->comment('0正常 1被否决');
            $table->unsignedSmallInteger('qualityScore')->default(0)->comment('手填质量评分');
            $table->unsignedInteger('submitTime')->default(0)->comment('巡检日期（第一次表单提交日期）');
            $table->tinyInteger('isSignature')->default(0)->comment('员工是否签名 0否 1是');

            $table->unsignedInteger('createdAt')->default(0)->comment('创建时间');
            $table->unsignedInteger('createdByUid')->default(0)->comment('创建人');
            $table->unsignedInteger('updatedAt')->default(0)->comment('修改时间');
            $table->unsignedInteger('updatedByUid')->default(0)->comment('修改人');
            $table->collation = 'utf8mb4_general_ci';
            $table->comment = '稽核 - 巡检报告';

            $table->unique('code', 'idx_code');
            $table->index('orderId', 'idx_orderId');
            $table->index('createdAt', 'idx_createdAt');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('cruise_check_details');
    }
}
